package com.da.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.da.common.StatusCode.ERROR_CODE;
import static com.da.common.StatusCode.SUCCESS_CODE;

/**
 * @author da
 * @time 2023/12/11 下午 10:32
 * 统一格式的响应对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result {
    private String msg;
    private int code;
    private Object data;

    public static Result success(String msg) {
        return new Result(msg, SUCCESS_CODE, null);
    }

    public static Result success(String msg, Object data) {
        return new Result(msg, SUCCESS_CODE, data);
    }

    public static Result error(String msg) {
        return new Result(msg, ERROR_CODE, null);
    }

    public static Result error(String msg, Object data) {
        return new Result(msg, ERROR_CODE, data);
    }

}
